﻿using System;
using System.Linq;

class BombingCuboids
{

    static int[] lettersHitCount = new int[91];

    const char Empty = ' ';

    static int totalHit = new int();

    static void Main()
    {
        int width, height, depth;

        string dimensions = Console.ReadLine();

        char[] separator = new char[] { ' ' };

        string[] dimensionStrings = dimensions.Split(separator, StringSplitOptions.RemoveEmptyEntries);

        width = int.Parse(dimensionStrings[0]);
        height = int.Parse(dimensionStrings[1]);
        depth = int.Parse(dimensionStrings[2]);

        char[, ,] cube = new char[width, height, depth];

        for (int currHight = 0; currHight < height; currHight++)
        {
            string[] plateRows = Console.ReadLine().Split(separator, StringSplitOptions.RemoveEmptyEntries);

            for (int currDepth = 0; currDepth < depth; currDepth++)
            {
                string currPlateRow = plateRows[currDepth];

                for (int currWidth = 0; currWidth < width; currWidth++)
                {
                    cube[currWidth, currHight, currDepth] = currPlateRow[currWidth];
                }
            }

            for (int currHeight = 0; currHeight < height; currHeight++)
            {
                for (int currDepth = 0; currDepth < depth; currDepth++)
                {
                    for (int currWidth = 0; currWidth < width; currWidth++)
                    {
                        Console.Write(cube[currWidth, currHight, currDepth]);
                    }
                    Console.WriteLine();
                }
            }

            int bombsCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < bombsCount; i++)
            {
                string[] bombValues = Console.ReadLine().Split(separator, StringSplitOptions.RemoveEmptyEntries);

                int bombWidth = int.Parse(bombValues[0]),
                bombHeight = int.Parse(bombValues[1]),
                bombDepth = int.Parse(bombValues[2]),
                power = int.Parse(bombValues[3]);


                DetonateBomb(cube, bombWidth, bombHeight, bombDepth, power);
                FallDown(cube);
            }

            PrintResult();
        }
    }

    private static void PrintResult()
    {
        Console.WriteLine(totalHit);

        for (int i = 0; i < lettersHitCount.Length; i++)
        {
            if (lettersHitCount[i] != 0)
            {
                Console.WriteLine("{0} {1}", (char)i, lettersHitCount[i]);
            }
        }
    }

    private static void FallDown(char[, ,] cube)
    {
        for (int pillarWidth = 0; pillarWidth < cube.GetLength(0); pillarWidth++)
			{
                    for (int pillarDepth = 0; pillarDepth < cube.GetLength(1); pillarDepth++)
			    {

                        FallDownPillar(cube, pillarWidth, pillarDepth);
			    }
			}
    }

private static void FallDownPillar(char[,,] cube,int pillarWidth,int pillarDepth)
{
    int pillarHeight = cube.GetLength(1);

    int bottom = 0;

    for (int currHeight = 0; currHeight < pillarHeight; currHeight++)
	{
        if (cube[pillarWidth, currHeight, pillarDepth] != Empty)
	    {
            if (currHeight != bottom)
        	{
		        cube[pillarWidth, bottom, pillarDepth] = cube[pillarWidth, currHeight, pillarDepth];
                cube[pillarWidth, currHeight, pillarDepth] = Empty;
            }
            
            bottom++;
	    }
	}
}

    private static void DetonateBomb(char[, ,] cube, int bombWidth, int bombHeight, int bombDepth, int power)
    {
        for (int currWidth = 0; currWidth < cube.GetLength(0); currWidth++)
        {
            for (int currHeight = 0; currHeight < cube.GetLength(1); currHeight++)
            {
                for (int currDepth = 0; currDepth < cube.GetLength(2); currDepth++)
                {
                    if (bombWidth - power <= currWidth && bombWidth + power >= currWidth)
                    {
                        
                    }
                    if ( cube[currWidth, currHeight, currDepth] == Empty)
	                {
                        int distSqarred = GetDistSquarred(currWidth, currDepth, currHeight, bombWidth, bombHeight, bombDepth);
                        int pSquarred = power * power;

                        if (distSqarred <= pSquarred)
                        {
                            char currLetter = cube[currWidth, currHeight, currDepth];
                            lettersHitCount[(int)currLetter]++;
                            totalHit++;

                            cube[currWidth, currHeight, currDepth] = Empty;
                        }
                    }
                }
            }
        }
        throw new NotImplementedException();
    }

    private static int GetDistSquarred(int currWidth, int currDepth, int currHeight, int bombWidth, int bombHeight, int bombDepth)
    {
        int deltaWith = currWidth - bombWidth,
        deltaHeight = currHeight - bombHeight,
        deltaDepth = currDepth - bombDepth;
        return deltaWith * deltaWith + deltaHeight * deltaHeight + deltaDepth * deltaDepth;
    }
}